<%--
  Created by IntelliJ IDEA.
  User: Lemon
  Date: 2020/6/11
  Time: 14:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>分类客户统计</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!-- 引入 ECharts 文件 -->
    <script src="${pageContext.request.contextPath}/static/js/echarts.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css"  media="all">
</head>
<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md12">
            <form class="layui-form" action="" style="margin-top:30px;">
                <div class="layui-form-item" style="text-align:center;">
                    <div class="layui-inline">
                        <label class="layui-form-label">分类</label>
                        <div class="layui-input-inline" style="width:150px;">
                            <select name="selectType" lay-filter="report-object">
                                <option value="2010" selected>客户信用度</option>
                                <option value="2020" >客户等级</option>
                                <option value="2030" >客户成熟度</option>
                                <option value="2040" >客户来源</option>
                                <option value="2050" >客户状态</option>
                                <option value="2060" >客户类别</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">统计粒度</label>
                        <div class="layui-input-inline" style="width:100px;">
                            <select name="action" lay-filter="select-action">
                                <option value="year" selected>年</option>
                                <option value="month" >月</option>
                                <option value="day">日</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">时间</label>
                        <div class="layui-input-inline" id="select-year-div" style="width:80px;">
                            <!-- <input name="date" id="time" class="layui-input"> -->
                            <select name="year" lay-filter="select-year">
                                <option value="2018" selected>2018</option>
                                <option value="2018" selected>2018</option>
                                <option value="2018" selected>2018</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-hide" id="select-month-div" style="width:80px;">
                            <select name="month" lay-filter="select-month">
                                <option value="01" selected>1月</option>
                                <option value="02">2月</option>
                                <option value="03">3月</option>
                                <option value="04">4月</option>
                                <option value="05">5月</option>
                                <option value="06">6月</option>
                                <option value="07">7月</option>
                                <option value="08">8月</option>
                                <option value="09">9月</option>
                                <option value="10">10月</option>
                                <option value="11">11月</option>
                                <option value="12">12月</option>
                            </select>
                        </div>
                        <div class="layui-input-inline  layui-hide" id="select-day-div" style="width:80px;">
                            <select name="day" lay-filter="select-day">
                                <option value="01" selected>01</option>
                            </select>
                        </div>
                        <button id="customerButton" class="layui-btn layui-btn-primary" type="button">确定</button>
                    </div>
                </div>
            </form>
            <div id="classifiedCustomerStatistics" style="width:100%;height:500px">
            </div>
        </div>
    </div>
</div>
</body>
<script src="${pageContext.request.contextPath}/static/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.use(['element','jquery','layer','form','laydate','layedit'], function() {
        var $ = layui.jquery
            ,element = layui.element;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;

        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('classifiedCustomerStatistics'));

        var  option = {
            title : {
                text: '客户新增趋势'
            },
            tooltip:{  //鼠标经过显示提示框
                show : true,
                trigger: "axis"
            },
            legend:{  //不同的线的类型
                data: ["客户新增量"]
            },
            toolbox:{  //工具栏
                show: true,
                feature:{
                    restore: {},
                    saveAsImage: {}
                }
            },
            dataZoom: [  //滚动条
                {
                    type: 'slider',
                    show: true,
                    start: 0,
                    end: 100
                }
            ],
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                name: "数量",
                type: 'value',
                max : 12,
                min : 0,
                splitNumber : 6,
            },
            yAxis: {
                name: "新增客户量",
                type: 'category',
                data: ["未分类","☆☆","☆☆☆☆☆","☆","☆☆☆","☆☆☆☆"]
            },

            series: [
                {
                    name: '客户新增量',
                    type: 'bar',
                    stack: '状态',
                    data: [7,2,2,1,0,0]
                }
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);

        //初始化年下拉框
        function init(){
            var year = new Date().getFullYear();

            var str = '';
            for(var i=year-10;i<=year+10;i++){
                if(i == year){
                    str += '<option value="' + i + '" selected>' + i + '</option>';
                }else{
                    str += '<option value="' + i + '">' + i + '</option>';
                }
            }
            $('select[name=year]').html(str);
            form.render("select");

        }
        init();

        //监听查询方式选择
        form.on('select(select-action)',function(data){
            if(data.value == 'day'){

                changeDays();
                $('#select-day-div').removeClass('layui-hide');
                $('#select-month-div').removeClass('layui-hide');

            }else if(data.value == 'month'){
                $('#select-day-div').addClass('layui-hide');
                $('#select-month-div').removeClass('layui-hide');
            } else{
                $('#select-day-div').addClass('layui-hide');
                $('#select-month-div').addClass('layui-hide');
            }

        });


        form.on('select(select-year)',function(data){
            changeDays();
        });

        form.on('select(select-month)',function(data){
            changeDays();
        });

        function changeDays(){
            var days = laydate.getEndDate($('select[name=month]').val(),$('select[name=year]').val());
            var str = '<option value="01" selected>01</option>';
            for(var i=2;i<=days;i++){
                var j = i >= 10 ? '' + i : '0' + i;
                str += '<option value="' + j + '">' + j + '</option>';
            }
            $('select[name=day]').html(str);
            form.render('select');
        }

    });
</script>

</html>